package com.homedroid.dal;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;

public class Client {

	public Socket nsocket; // Network Socket

	public Client() throws IOException{
		SocketAddress sockaddr = new InetSocketAddress("homedroid.no-ip.org",22222);
		nsocket = new Socket();
		nsocket.connect(sockaddr, 5000); // 10 second connection timeout
	}
	
	public void SendDataToNetwork(String cmd) throws IOException { // You run this from the main
		
		System.out.println("Send: " + cmd);
	    PrintWriter pw = new PrintWriter(nsocket.getOutputStream(), true);
	    pw.println(cmd);
	    pw.flush();
	}
	
	public String ReceiveDataFromNetwork() throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(nsocket.getInputStream()));
		String got = br.readLine();
		System.out.println("Got: " + got);
		return got;
	}
	

}
